<template>
  <div>
    <tableComponents :isShow="false" :isHaveExport="false" :isHaveAdd="false" :isHavePagination="false">
      <template v-slot:table>
        <el-row>
          <el-col :span="20" class="pd_20">
            <el-col :span="4" class="clear_btn">
              <el-button type="primary" @click="clear_btn('index')">清空会员</el-button>
            </el-col>
            <el-col :span="4" class="clear_btn">
              <el-button type="danger" @click="clear_btn('news')">清空新闻</el-button>
            </el-col>
            <el-col :span="4" class="clear_btn">
              <el-button type="primary" @click="clear_btn('gallery')">清空图库</el-button>
            </el-col>
            <el-col :span="4" class="clear_btn">
              <el-button type="primary" @click="clear_btn('product_cate')">清空商品分类</el-button>
            </el-col>
            <el-col :span="4" class="clear_btn">
              <el-button type="primary" @click="clear_btn('sku')">清空商品sku</el-button>
            </el-col>
            <el-col :span="4" class="clear_btn">
              <el-button type="primary" @click="clear_btn('product')">清空商品</el-button>
            </el-col>
            <el-col :span="4" class="clear_btn">
              <el-button type="primary" @click="clear_btn('product_stock')">清空商品库存</el-button>
            </el-col>
            <el-col :span="4" class="clear_btn">
              <el-button type="danger" @click="clear_btn('supplier')">清空商户商品</el-button>
            </el-col>
            <el-col :span="4" class="clear_btn">
              <el-button type="primary" @click="clear_btn('admin')">清空管理员</el-button>
            </el-col>
            <el-col :span="4" class="clear_btn">
              <el-button type="danger" @click="clear_btn('plugin')">重置插件</el-button>
            </el-col>
            <el-col :span="4" class="clear_btn">
              <el-button type="primary" @click="clear_btn('menu')">重置栏目</el-button>
            </el-col>
            <el-col :span="4" class="clear_btn">
              <el-button type="danger" @click="clear_btn('config')">重置配置</el-button>
            </el-col>

            <el-col :span="4" class="clear_btn">
              <el-button type="primary" @click="clear_btn('user_gx')">重置推荐关系</el-button>
            </el-col>
            <el-col :span="4" class="clear_btn">
              <el-button type="danger" @click="clear_btn('user_attach')">重置用户市场人数</el-button>
            </el-col>
            <el-col :span="4" class="clear_btn">
              <el-button type="primary" @click="clear_btn('admin_money')">平台账户金额清零</el-button>
            </el-col>
            <el-col :span="4" class="clear_btn">
              <el-button type="danger" @click="clear_btn('set_index')">添加配置字段</el-button>
            </el-col>
            <el-col :span="4" class="clear_btn">
              <el-button type="primary" @click="clear_btn('platoon')">清空公排架构</el-button>
            </el-col>
          </el-col>
        </el-row>
      </template>
    </tableComponents>
  </div>
</template>
<script>
import axios from "axios";
import qs from "qs";
var md5 = require("md5");
export default {
  name: "clear",
  data () {
    return {};
  },
  methods: {
    clear_btn (type) {
      this.$swal({
        title: "您确定要删除这条信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思"
      }).then(willDelete => {
        if (willDelete.value) {
          let method = "";
          if (type == "set_index") {
            method = "/api/common/setting/index";
          } else {
            method = "/api/admin/emptys/" + type;
          }
          var params = {};
          var uid = localStorage.getItem("adminuid") || "";
          var time = parseInt(new Date().getTime() / 1000) + "";
          var admin_key = localStorage.getItem("admin_key") || "";
          var str = qs.stringify(params);
          var url = "";
          if (str == "") {
            url =
              "admin_key=" +
              admin_key +
              "&headuid=" +
              uid +
              "&timestamp=" +
              time +
              "&meid=" +
              "" +
              "&extra=" +
              "";
          } else {
            url =
              str +
              "&admin_key=" +
              admin_key +
              "&headuid=" +
              uid +
              "&timestamp=" +
              time +
              "&meid=" +
              "" +
              "&extra=" +
              "";
          }
          var arr = url.split("&");
          for (var i in arr) {
            if (arr[i].indexOf("%") >= 0) {
              arr[i] = decodeURIComponent(arr[i]);
            }
          }
          var urlStr = arr.sort().join("&");
          params.sign = md5("@" + urlStr + "@");

          axios
            .post(method, qs.stringify(params), {
              headers: {
                headuid: uid,
                timestamp: time,
                meid: "",
                extra: ""
              },
              timeout: 600000
            })
            .then(res => {
              if (res.data.code == 200) {
                this.$swal("操作成功！", "您已经清空了这条信息。", "success");
              } else {
                this.$swal("操作失败！", res.data.result, "error");
              }
            });
        }
      });
    }
  }
};
</script>
<style scoped>
.clear_btn {
  padding: 10px 0;
}
</style>
